package com.bootdo.wx.api;

import com.bootdo.common.utils.R;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.wx.service.MemberApplyService;
import com.bootdo.wx.service.OrderTeamMoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/api/team")
public class ApiTeamMoneyController {

    @Autowired
    private OrderTeamMoneyService orderTeamMoneyService;

    @Autowired
    private MemberApplyService memberApplyService;


    /***
     * 申请升级
     * @param params
     * @return
     */
    @PostMapping( "/applyUpgrade")
    @ResponseBody
    public R applyUpgrade(@RequestBody Map<String, Object> params){
        if (!params.containsKey("userId")|| StringUtils.isBlank(params.get("userId").toString())

        ){
            return R.error("参数错误");
        }
        try{
            return memberApplyService.applyUpgrade(params);

        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }


    /**
     * 获取升级特权
     * @param params 0用户升级团长 1 团长升级核心 2 核心升级合伙人 3 合伙人保级
     * @return
     */
    @PostMapping( "/getUpgradeRules")
    @ResponseBody
    public R getUpgradeRules(@RequestBody Map<String, Object> params){
        if (!params.containsKey("userId")|| StringUtils.isBlank(params.get("userId").toString())
        ||!params.containsKey("status")|| StringUtils.isBlank(params.get("status").toString())
        ){
            return R.error("参数错误");
        }
        try{
            return orderTeamMoneyService.getUpgradeRules(params);

        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }
}
